/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Collection;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;


//select R from Resource R join R.ownerShipConfigurations oc left join oc.branches b  where R.active = true and R.company.id = :companyId and (b.id is null or  b.id = :branchId)
//SELECT e FROM Employee e LEFT JOIN e.address a ORDER BY a.city
//SELECT p FROM Player p LEFT JOIN p.shoeCompany sc



/**
 *
 * @author Administrador		
 */
@Entity
@Table(name = "product")
@NamedQueries({
    @NamedQuery(name = "Product.findAll", query = "SELECT p FROM Product p"),							
    @NamedQuery(name = "Product.findByActiveSubstanceId", query = "SELECT p FROM Product p WHERE p.activeSubstanceId.activeSubstanceId = :activeSubstanceId"),
    @NamedQuery(name = "Product.findByActiveSubstanceIdByActive", query = "SELECT p FROM Product p WHERE p.activeSubstanceId.activeSubstanceId = :activeSubstanceId AND p.active = :active"),
    @NamedQuery(name = "Product.findByProviderId", query = "SELECT p FROM Product p WHERE p.productPK.providerId = :providerId"),
    @NamedQuery(name = "Product.findByActiveByName", query = "SELECT p FROM Product p WHERE p.active = :active AND p.name like :name"),
    @NamedQuery(name = "Product.findByActiveByCode", query = "SELECT p FROM Product p WHERE p.active = :active AND p.code like :code"),
    @NamedQuery(name = "Product.findByActiveByCodeBar", query = "SELECT p FROM Product p WHERE p.active = :active AND p.codeBar like :codeBar"),
    @NamedQuery(name = "Product.findByProviderIdByActiveByName", query = "SELECT p FROM Product p WHERE p.productPK.providerId = :providerId AND p.active = :active AND p.name like :name"),
    @NamedQuery(name = "Product.findByProviderIdByActiveByCode", query = "SELECT p FROM Product p WHERE p.productPK.providerId = :providerId AND p.active = :active AND p.code like :code"),
    @NamedQuery(name = "Product.findByProviderIdByActiveByCodeBar", query = "SELECT p FROM Product p WHERE p.productPK.providerId = :providerId AND p.active = :active AND p.codeBar like :codeBar"),
    @NamedQuery(name = "Product.findByProviderIdByActive", query = "SELECT p FROM Product p WHERE p.productPK.providerId = :providerId AND p.active = :active"),
    @NamedQuery(name = "Product.findByProductId", query = "SELECT p FROM Product p WHERE p.productPK.productId = :productId"),
    @NamedQuery(name = "Product.findByProductIdMax", query = "SELECT max(p.productPK.productId) FROM Product p"),
    @NamedQuery(name = "Product.findByProductIdByActive", query = "SELECT p FROM Product p WHERE p.productPK.productId = :productId AND p.active = :active"),
    @NamedQuery(name = "Product.findByProductIdByProviderId", query = "SELECT p FROM Product p WHERE p.productPK.productId = :productId AND p.productPK.providerId = :providerId"),
    @NamedQuery(name = "Product.findByName", query = "SELECT p FROM Product p WHERE p.name = :name"),
    @NamedQuery(name = "Product.findByGenericName", query = "SELECT p FROM Product p WHERE p.genericName = :genericName"),
    @NamedQuery(name = "Product.findByGeneralIndication", query = "SELECT p FROM Product p WHERE p.generalIndication = :generalIndication"),
    @NamedQuery(name = "Product.findByPresentation", query = "SELECT p FROM Product p WHERE p.presentation = :presentation"),
    @NamedQuery(name = "Product.findByCheckHealth", query = "SELECT p FROM Product p WHERE p.checkHealth = :checkHealth"),
    @NamedQuery(name = "Product.findByCode", query = "SELECT p FROM Product p WHERE p.code = :code"),
    @NamedQuery(name = "Product.findByCodeBar", query = "SELECT p FROM Product p WHERE p.codeBar = :codeBar"),
    @NamedQuery(name = "Product.findByRemarkComposition", query = "SELECT p FROM Product p WHERE p.remarkComposition = :remarkComposition"),
    @NamedQuery(name = "Product.findByHaveExpirationDate", query = "SELECT p FROM Product p WHERE p.haveExpirationDate = :haveExpirationDate"),
    @NamedQuery(name = "Product.findByActive", query = "SELECT p FROM Product p WHERE p.active = :active")})
public class Product implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ProductPK productPK;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @Column(name = "genericName")
    private String genericName;
    @Column(name = "generalIndication")
    private String generalIndication;
    @Basic(optional = false)
    @Column(name = "presentation")
    private String presentation;
    @Column(name = "checkHealth")
    private String checkHealth;
    @Column(name = "code")
    private String code;
    /*
    @Column(name = "codeBar")
    private BigInteger codeBar;
    */
    @Column(name = "codeBar")
    private String codeBar;
    @Column(name = "remarkComposition")
    private String remarkComposition;
    @Column(name = "haveExpirationDate")
    private Boolean haveExpirationDate;
    @Basic(optional = false)
    @Column(name = "active")
    private boolean active;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "product")
    private Collection<Productattributes> productattributesCollection;
    @OneToMany(mappedBy = "product")
    private Collection<Composition> compositionCollection;
    
    /*
    @NamedQuery(name = "Product.findLeft", query = "SELECT p FROM Product p LEFT JOIN p.pharmacyproductCollection pp where p.active = true"),     
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "product")
    private Collection<Pharmacyproduct> pharmacyproductCollection;
    */
    
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "product")
    private Pharmacyproduct pharmacyProduct; 
    
	@JoinColumn(name = "providerId", referencedColumnName = "providerId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Provider provider;
    @JoinColumn(name = "activeSubstanceId", referencedColumnName = "activeSubstanceId")
    @ManyToOne
    private Activesubstance activeSubstanceId;
    @JoinColumns({
        @JoinColumn(name = "pharmacyId", referencedColumnName = "pharmacyId"),
        @JoinColumn(name = "userId", referencedColumnName = "userId")})
    @ManyToOne
    private Userpharmacy userpharmacy;

    public Product() {
    }

    public Product(ProductPK productPK) {
        this.productPK = productPK;
    }

    public Product(ProductPK productPK, String name, String presentation, boolean active) {
        this.productPK = productPK;
        this.name = name;
        this.presentation = presentation;
        this.active = active;
    }
    
    public Pharmacyproduct getPharmacyProduct() {
		return pharmacyProduct;
	}

	public void setPharmacyProduct(Pharmacyproduct pharmacyProduct) {
		this.pharmacyProduct = pharmacyProduct;
	}
    
    public Product(int providerId, int productId) {
        this.productPK = new ProductPK(providerId, productId);
    }

    public ProductPK getProductPK() {
        return productPK;
    }

    public void setProductPK(ProductPK productPK) {
        this.productPK = productPK;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGenericName() {
        return genericName;
    }

    public void setGenericName(String genericName) {
        this.genericName = genericName;
    }

    public String getGeneralIndication() {
        return generalIndication;
    }

    public void setGeneralIndication(String generalIndication) {
        this.generalIndication = generalIndication;
    }

    public String getPresentation() {
        return presentation;
    }

    public void setPresentation(String presentation) {
        this.presentation = presentation;
    }

    public String getCheckHealth() {
        return checkHealth;
    }

    public void setCheckHealth(String checkHealth) {
        this.checkHealth = checkHealth;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
    /*
    public BigInteger getCodeBar() {
        return codeBar;
    }

    public void setCodeBar(BigInteger codeBar) {
        this.codeBar = codeBar;
    }
	*/
    public String getCodeBar() {
        return codeBar;
    }

    public void setCodeBar(String codeBar) {
        this.codeBar = codeBar;
    }
    public String getRemarkComposition() {
        return remarkComposition;
    }

    public void setRemarkComposition(String remarkComposition) {
        this.remarkComposition = remarkComposition;
    }

    public Boolean getHaveExpirationDate() {
        return haveExpirationDate;
    }

    public void setHaveExpirationDate(Boolean haveExpirationDate) {
        this.haveExpirationDate = haveExpirationDate;
    }

    public boolean getActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

   // @XmlTransient
    public Collection<Productattributes> getProductattributesCollection() {
        return productattributesCollection;
    }

    public void setProductattributesCollection(Collection<Productattributes> productattributesCollection) {
        this.productattributesCollection = productattributesCollection;
    }

  //  @XmlTransient
    public Collection<Composition> getCompositionCollection() {
        return compositionCollection;
    }

    public void setCompositionCollection(Collection<Composition> compositionCollection) {
        this.compositionCollection = compositionCollection;
    }

   // @XmlTransient
    /*
    public Collection<Pharmacyproduct> getPharmacyproductCollection() {
        return pharmacyproductCollection;
    }

    public void setPharmacyproductCollection(Collection<Pharmacyproduct> pharmacyproductCollection) {
        this.pharmacyproductCollection = pharmacyproductCollection;
    }
	*/
    public Provider getProvider() {
        return provider;
    }

    public void setProvider(Provider provider) {
        this.provider = provider;
    }

    public Activesubstance getActiveSubstanceId() {
        return activeSubstanceId;
    }

    public void setActiveSubstanceId(Activesubstance activeSubstanceId) {
        this.activeSubstanceId = activeSubstanceId;
    }

    public Userpharmacy getUserpharmacy() {
        return userpharmacy;
    }

    public void setUserpharmacy(Userpharmacy userpharmacy) {
        this.userpharmacy = userpharmacy;
    }
/*
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (productPK != null ? productPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Product)) {
            return false;
        }
        Product other = (Product) object;
        if ((this.productPK == null && other.productPK != null) || (this.productPK != null && !this.productPK.equals(other.productPK))) {
            return false;
        }
        return true;
    }

    @Override*/
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Product[ productPK=" + productPK + " ]";
    }
    
}
